package com.jiawei.controller;

import com.jiawei.service.AccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : willian fu
 * @date : 2019/12/11
 */
@RestController
public class LoginController {

    @Autowired
    private AccessService accessService;

    /**
     * 登录接口
     * @param user 用户名
     * @param password 密码
     * @return 登录结果
     */
    @GetMapping("login")
    public Object login(@RequestParam(value = "account") String user,
                        @RequestParam(value = "password") String password){
        return accessService.login(user, password);
    }

    /**
     * 用户注册
     * @param user 用户名
     * @param password 密码
     * @param code 验证码
     * @return 注册结果
     */
    @GetMapping("register")
    public Object registry(@RequestParam(value = "account") String user,
                           @RequestParam(value = "password") String password,
                           @RequestParam(value = "code") String code){
        return accessService.registry(user, password, code);
    }

    /**
     * 获取注册验证码
     * @param user 用户名
     * @return 验证码
     */
    @GetMapping("code")
    public Object getCode(@RequestParam(value = "account") String user){
        return accessService.getCode(user);
    }
}
